package com.ruoyi.project.mahjong.controller;

import java.util.List;

import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.framework.redis.RedisCache;
import com.ruoyi.project.system.domain.SysUser;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.mahjong.domain.TLogManage;
import com.ruoyi.project.mahjong.service.ITLogManageService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 日志管理Controller
 *
 * @author ruoyi
 * @date 2023-07-18
 */
@RestController
@RequestMapping("/mahjong/manage")
public class TLogManageController extends BaseController
{
    @Autowired
    private ITLogManageService tLogManageService;
    @Autowired
    private RedisCache redisCache;
    /**
     * 查询日志管理列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:manage:list')")
    @GetMapping("/list")
    public TableDataInfo list(TLogManage tLogManage)
    {

        SysUser user1 = SecurityUtils.getLoginUser().getUser();
        Long shopId = redisCache.getCacheObject(Constants.SHOP_SUF + user1.getUserId());
        tLogManage.setCreateBy(shopId.toString());
        tLogManage.setCreateBy(shopId.toString());
        startPage();
        List<TLogManage> list = tLogManageService.selectTLogManageList(tLogManage);
        return getDataTable(list);
    }

    /**
     * 导出日志管理列表
     */
    @PreAuthorize("@ss.hasPermi('mahjong:manage:export')")
    @Log(title = "日志管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TLogManage tLogManage)
    {
        List<TLogManage> list = tLogManageService.selectTLogManageList(tLogManage);
        ExcelUtil<TLogManage> util = new ExcelUtil<TLogManage>(TLogManage.class);
        return util.exportExcel(list, "manage");
    }

    /**
     * 获取日志管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('mahjong:manage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(tLogManageService.selectTLogManageById(id));
    }

    /**
     * 新增日志管理
     */
    @PreAuthorize("@ss.hasPermi('mahjong:manage:add')")
    @Log(title = "日志管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TLogManage tLogManage)
    {
        SysUser user1 = SecurityUtils.getLoginUser().getUser();
        Long shopId = redisCache.getCacheObject(Constants.SHOP_SUF + user1.getUserId());
        tLogManage.setCreateBy(shopId.toString());
        return toAjax(tLogManageService.insertTLogManage(tLogManage));
    }

    /**
     * 修改日志管理
     */
    @PreAuthorize("@ss.hasPermi('mahjong:manage:edit')")
    @Log(title = "日志管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TLogManage tLogManage)
    {

        SysUser user1 = SecurityUtils.getLoginUser().getUser();
        Long shopId = redisCache.getCacheObject(Constants.SHOP_SUF + user1.getUserId());
        tLogManage.setCreateBy(shopId.toString());
        return toAjax(tLogManageService.updateTLogManage(tLogManage));
    }

    /**
     * 删除日志管理
     */
    @PreAuthorize("@ss.hasPermi('mahjong:manage:remove')")
    @Log(title = "日志管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tLogManageService.deleteTLogManageByIds(ids));
    }
}
